﻿/*---------------------------------------------------------------------------------------
 
	File Name:			register.js	
	Create Time:		Jun 17th, 2007.
	Author:				Seamuz
	All Rights Reserved (c) Huohai Co.,Ltd
 
----------------------------------------------------------------------------------------*/

function checkregister()
{
	var f = form('RegisterForm');
	var len = bytes(f.username.value);
 
	if (len < minlength || len > maxlength || f.username.value.length > 40)
	{
		alert('会员名只能由' + minlength + '-' + maxlength + '字节组成，一个中文字符占2个字节，不能含空格或特殊符号');
		f.username.focus();
		return false;
	}
	if (specialchar(f.username.value))
	{
		alert('会员名不能包含特殊符号');
		f.username.focus();
		return false;
	}
	if (isReserve(f.username.value))
	{
		alert('为系统保留帐号，不可注册！');
		f.username.focus();
		return false;
	}
	if (badword(f.username.value))
	{
		alert('严禁使用不文明字词 !');
		f.username.focus();
		return false;
	}
	if (f.password.value == '' || f.password.value.length < 6 || f.password.value.length > 20)
	{
		alert('密码不得为空或包含空格，长度6-20');
		f.password.focus();
		return false;
	}
	if (f.password.value != f.confirmpassword.value)
	{
		alert('两次密码填写不一致');
		f.password.focus();
		return false;
	}
	if (f.email.value.search(/^[^\s@:"'<>,&]{2,}@[^\[\.]+\.[^\[]{2,}$/gi) < 0)
	{
		alert('请正确填写你的邮件地址');
		f.email.focus();
		return false;
	}
	if (f.email.value.length >= 45)
	{
		alert('请正确填写你的邮件地址');
		f.email.focus();
		return false;
	}
	
	if (f.loginquestion.options[f.loginquestion.selectedIndex].value != '')
	{
		if (f.loginanswer.value == '')
		{
			alert("您选择了安全问题，请设置相应的答案！");
			f.loginanswer.focus();
			return false;
		}
	}
	
	if (f.verification)
	{
		if (f.verification.value == '')
		{
			alert('请输入验证码');
			f.verification.focus();
			return false;
		}
	}	
	return true;
}

function badword(name)
{
	var badwords = '妈的|你妈|妈b|妈比|fuck|shit|我日|法轮';
	if (badwords.indexOf('|') != -1)
	{
		return false;
	}
	var bw= badwords.split('|');
	for(i=0; i<=bw.length; i++)
	{
		if (name.toLowerCase().indexOf(bw[i]) != -1)
		{
			return true;
		}
	}
	return false;
}  
function isReserve(name)
{
	var r = "|" + reserveNames + "|";
	return r.indexOf("|" + name + "|") > -1;
}

function checkname(username)
{
	var f = form('RegisterForm');
	var len = bytes(username.value);
	if (len == 0) return;
	if (len < minlength || len > maxlength || username.value.length > 40)
	{
		errormsg('会员名只能由' + minlength + '-' + maxlength + '字节组成，一个中文字符占2个字节，不能含空格或特殊符号');
		f.username.focus();
		return false;
	}
	if (specialchar(username.value))
	{
		errormsg('会员名不能包含特殊符号');
		username.focus();
		return false;
	}
	
	if (isReserve(username.value))
	{
		errormsg('为系统保留帐号，不可注册！');
		f.username.focus();
		return false;
	}
	if (badword(username.value))
	{
		errormsg('严禁使用不文明字词 !');
		username.focus();
		return false;
	}
	
	var request  = new Ajax(); 
	request.get("register.aspx?username=" + escape(username.value) + "&timestamp=" + (new Date().getTime()), showresult);
}

function showresult(xmlobj)
{
	if (xmlobj.readyState == 4)
	{
		var response	= xmlobj.responseText;
		var result		= $("result");
		if (response == "0")
		{
			result.src= "images/icon/pass.gif";
		}
		else
		{
			result.src= "images/icon/unpass.gif";
			setTimeout("focusname();", 3000); 
		}
	}
}
function focusname()
{
	var f = form('RegisterForm');
	f.username.focus();
}

function onentername()
{ 
	 clear();
	 clearerror();
}
function clear()
{
	$("result").src= "images/icon/test.gif";
}

function clearerror()
{
	$("errormsg").innerHTML = "";
	$("errormsg").style.display = "none";
}
function errormsg(msg)
{
	$("errormsg").innerHTML = msg;
	$("errormsg").style.display = "";
	$("result").src= "images/icon/unpass.gif";
}